<template>
	<view class="content">
		<!--标题-->
		<view class="content_1">
			<view class="title_1">房屋租赁前情况记录</view>
		</view>
		<!--账单图片-->
		<view class="content_2" @click="toUploadimg">
			<view class="bill" v-if="uploadstate == '' || uploadstate == '-3' || uploadstate == '0'">请上传账单</view>
			<image class="bill" v-if="uploadstate == '1'" :src="uploadimg"></image>
		</view>
		<!--输入租金-->
		<view class="content_3">
			<view class="input_view">
				<view class="input_name">租金</view>
				<input class="input" placeholder="请输入金额" type="digit" @input="getMoneyInput"></input>
			</view>
		</view>
		<!--底部选择房间-->
		<view class="content_4" v-if="room_id==1" @click="toChooseroom">
			选择房间
		</view>
		<view class="content_4" v-else @click="toChooseroom">
			发送
		</view>
	</view>
</template>

<script>
	//导入接口请求文件
	import {
		Request
	} from '../../../../utils/request.js';
	//定义getApp对象
	const app = getApp();
	export default {
		data() {
			return {
				uploadstate: '',
				uploadimg: '',
				system_url: '',
				room_id: 0,
			}
		},
		onLoad(option) {
			if (option.room_id) {
				this.room_id = option.room_id
			}
		},
		methods: {
			toUploadimg: function() {
				new Request('landboos/Create_Receipt/UploadReceiptPhoto').uploadImage(
					() => {
						return {
							'user': 'test'
						}
					},
					(res) => {
						console.log(res)
						this.photo_id = res.photo_id
						this.uploadstate = res.code
						this.uploadimg = res.show_url;
						this.system_url = res.system_url
					}
				)
			},


			//获取用户输入
			getMoneyInput: function(e) {
				this.moneyinput = e.target.value
				console.log(e.target.value)
			},
			//跳转至选择房间
			toChooseroom: function() {
				if (this.photo_id == '' || this.photo_id == undefined) {
					new Request().showToast('请上传图片');
					return;
				}
				if (this.moneyinput == '' || this.moneyinput == undefined) {
					new Request().showToast('请输入租金');
					return;
				}
				
				if (this.room_id == 0) {
					uni.navigateTo({
						url: '/pages/mine/owner/takephoto/chooseroom?image_id=' + this.photo_id +
							'&rentmoney=' + this.moneyinput + '&system_url=' + this.system_url
					})
				} else {
					new Request('landboos/Create_Receipt/ChooseRoom').request(
						() => {
							return 'POST'
						},
						() => {
							return {
								openid: app.globalData.openid,
								room_id: this.room_id,
								rentmoney: this.moneyinput,
								image_id: this.photo_id,
								show_img: this.system_url,
								DevelopVersion: app.globalData.DevelopVersion,
								project: app.globalData.project,
								userid: app.globalData.userid,
							}
						},
						(res) => {
							if (res.data.status == '-1') {
								new Request().showToast('房间已经逾期了', 'none', () => {});
							} else if (res.data.status == '-2') {
								new Request().showToast('未临期不可上传账单', 'none', () => {});
							} else if (res.data.status == '-3') {
								new Request().showToast('拒绝入住的房间不可上传账单', 'none', () => {});
							} else if (res.data.code == '0') {
								new Request().showToast('房间还没出租', 'none', () => {});
							} else if (res.data.code == '1') {
								uni.navigateBack({
									delta: 3,
									success: (res) => {
										uni.showToast({
											title: '发送成功',
											icon: 'none',
											position: 'center',
										})
									}
								})
							}
						}
					)
				}
				
			}
		}
	}
</script>

<style>
	page {
		background-color: #F9F9F9;
	}

	/*
		标题样式
	*/
	.content_1 {
		margin-top: 30upx;
	}

	.title_1 {
		height: 50upx;
		line-height: 50upx;
		font-size: 36upx;
		color: #B3E9DC;
		text-align: center;
	}

	/*
		账单图片样式
	*/
	.content_2 {
		margin: 0 10upx;
		margin-top: 80upx;
	}

	.bill {
		height: 325upx;
		width: 100%;
		background-color: #9a9a9a;
		text-align: center;
		color: #FFFFFF;
		line-height: 325upx;
	}

	/*
		输入租金样式
	*/
	.content_3 {
		margin-top: 80upx;
	}

	.input_view {
		height: 100upx;
		padding-left: 30upx;
		display: flex;
		align-items: center;
		background-color: #FFFFFF;
	}

	.input_name {
		height: 44upx;
		line-height: 44upx;
		font-size: 32upx;
		color: #101010;
		margin-right: 80upx;
	}

	.input {
		height: 40upx;
		line-height: 40upx;
		font-size: 28upx;
	}

	/*
		底部选择房间样式
	*/
	.content_4 {
		position: fixed;
		z-index: 999;
		bottom: 0upx;
		left: 0upx;
		width: 750upx;
		height: 72upx;
		background-color: #63D0D5;
		text-align: center;
		line-height: 72upx;
		color: #FFFFFF;
		font-size: 28upx;
	}
</style>
